﻿package mortal.game.view.copy.ChallengeCopy.newView
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.ChallengeCopy.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class ChallengeMagicTowerWin extends BaseWindow
    {
        private var _copyList:GTileList;
        private var _timeClearBtn:GLoadedButton;
        private var _leftTime:SecTimerView;
        private var _leftTimeTxt:GTextFiled;
        private var _challengeData:ChallengeData;
        private static var _instance:ChallengeMagicTowerWin;

        public function ChallengeMagicTowerWin(param1:ILayer = null)
        {
            super(param1);
            setSize(766, 570);
            title = Language.getString(35114);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(6, 36, 760, 510, this));
            this._copyList = UIFactory.tileList(8, 25, 750, 542, this);
            this._copyList.columnWidth = 183;
            this._copyList.rowHeight = 404;
            this._copyList.horizontalGap = 5;
            this._copyList.setStyle("cellRenderer", ChallengeMagicTowerRender);
            this._copyList.selectable = false;
            this._leftTimeTxt = UIFactory.gTextField(Language.getString(35112), 358 - 49, 548, 100, 20, this);
            this._leftTime = UIFactory.secTimeView(Language.getString(30055), 420 - 49, 548, 0, 0, this, GlobalStyle.textFormatLv);
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.autoSize = TextFieldAutoSize.LEFT;
            this._leftTime.setParse(Language.getString(30056));
            this._leftTime.configEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            this._timeClearBtn = UIFactory.gLoadedButton(ImagesConst.FashionExpandBtn_upSkin, 485 - 49, 547, 24, 25, this);
            this._timeClearBtn.configEventListener(MouseEvent.CLICK, this.timeClearHandler);
            NetDispatcher.addCmdListener(ServerCommand.ChallengeClearCDSuccess, this.updateLeftTime);
            this.updateLeftTime();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.ChallengeClearCDSuccess, this.updateLeftTime);
            this._copyList.dispose(param1);
            this._copyList = null;
            this._timeClearBtn.dispose(param1);
            this._timeClearBtn = null;
            this._leftTime.dispose(param1);
            this._leftTime = null;
            this._leftTimeTxt.dispose(param1);
            this._leftTimeTxt = null;
            this._challengeData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function timeClearHandler(event:MouseEvent) : void
        {
            var _loc_2:Object = {code:GameConst.ChallengeCopyCode, leftTime:this._leftTime.getLeftTime()};
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChallengeClearCD, _loc_2));
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (_loc_2 == 0)
            {
                if (this.contains(this._leftTime))
                {
                    this.removeChild(this._leftTime);
                }
                if (this.contains(this._timeClearBtn))
                {
                    this.removeChild(this._timeClearBtn);
                }
                if (this.contains(this._leftTimeTxt))
                {
                    this.removeChild(this._leftTimeTxt);
                }
                Cache.instance.copy.challengCopy.residuettimes = 0;
            }
            return;
        }// end function

        public function set tower(param1:int) : void
        {
            var _loc_3:Object = null;
            var _loc_5:TChallengeCopy = null;
            var _loc_6:int = 0;
            this._challengeData = Cache.instance.copy.challengCopy.getDataByTowerAndSection(param1, 5);
            var _loc_2:* = new DataProvider();
            var _loc_4:int = 4;
            while (_loc_6 < 4)
            {
                
                _loc_5 = ChallengeCopyConfig.instance.getDataByTowerAndSectionAndDif(param1, 5, (_loc_6 + 1));
                if (_loc_5)
                {
                    _loc_3 = {data:_loc_5, index:_loc_6};
                    _loc_2.addItem(_loc_3);
                }
                _loc_6++;
            }
            this._copyList.dataProvider = _loc_2;
            return;
        }// end function

        private function updateLeftTime(param1:Object = null) : void
        {
            var _loc_2:* = Cache.instance.copy.challengCopy.residuettimes;
            if (_loc_2 > 3600)
            {
                this._leftTime.setParse(Language.getString(30055));
            }
            else if (_loc_2 < 3600)
            {
                this._leftTime.setParse(Language.getString(30056));
            }
            this._leftTime.setLeftTime(Cache.instance.copy.challengCopy.residuettimes);
            return;
        }// end function

        public static function get instance() : ChallengeMagicTowerWin
        {
            if (_instance == null)
            {
                _instance = new ChallengeMagicTowerWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
